﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverNes.Emulator.Extensions
{
	public static class ArrayExtensions
	{
		public static U[] Map<T, U>(this T[] input, Func<T, U> functor)
		{
			if (input == null)
				throw new ArgumentNullException("input");
			if (functor == null)
				throw new ArgumentNullException("functor");

			U[] result = new U[input.Length];
			for (int i = 0; i < input.Length; i++)
			{
				result[i] = functor(input[i]);
			}

			return result;
		}

		public static void Map<T, U>(this T[] input, U[] output, Func<T, U> functor)
		{
			if (input == null)
				throw new ArgumentNullException("input");
			if (output == null)
				throw new ArgumentNullException("output");
			if (functor == null)
				throw new ArgumentNullException("functor");
			if (input.Length == output.Length)
				throw new ArgumentException("input length must be equal to output length");

			for (int i = 0; i < input.Length; i++)
			{
				output[i] = functor(input[i]);
			}
		}
	}
}
